{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 数据归一化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 最值归一化 Normalization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([67, 47, 35,  5, 82, 68, 49, 92, 21, 57, 69, 81, 87,  9,  3,  8, 66,\n        8, 20, 39, 25, 55,  2, 74, 54, 30, 59,  2, 69, 74, 16, 36, 85, 81,\n       54, 40, 22, 17, 86, 71, 93, 37, 48, 67,  2, 56, 31, 26, 61,  7, 74,\n       89, 23, 57, 49, 86, 57, 69, 13, 71, 25, 29,  7, 17, 61, 27,  0, 88,\n       23, 23, 42, 12,  2, 32, 11, 31, 68, 73, 99,  1, 18, 76, 96, 35, 44,\n       72, 57, 74, 49, 75, 47, 37, 73, 96, 71, 42,  0, 86, 81,  6])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.random.randint(0,100,size=100)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.67676768,  0.47474747,  0.35353535,  0.05050505,  0.82828283,\n        0.68686869,  0.49494949,  0.92929293,  0.21212121,  0.57575758,\n        0.6969697 ,  0.81818182,  0.87878788,  0.09090909,  0.03030303,\n        0.08080808,  0.66666667,  0.08080808,  0.2020202 ,  0.39393939,\n        0.25252525,  0.55555556,  0.02020202,  0.74747475,  0.54545455,\n        0.3030303 ,  0.5959596 ,  0.02020202,  0.6969697 ,  0.74747475,\n        0.16161616,  0.36363636,  0.85858586,  0.81818182,  0.54545455,\n        0.4040404 ,  0.22222222,  0.17171717,  0.86868687,  0.71717172,\n        0.93939394,  0.37373737,  0.48484848,  0.67676768,  0.02020202,\n        0.56565657,  0.31313131,  0.26262626,  0.61616162,  0.07070707,\n        0.74747475,  0.8989899 ,  0.23232323,  0.57575758,  0.49494949,\n        0.86868687,  0.57575758,  0.6969697 ,  0.13131313,  0.71717172,\n        0.25252525,  0.29292929,  0.07070707,  0.17171717,  0.61616162,\n        0.27272727,  0.        ,  0.88888889,  0.23232323,  0.23232323,\n        0.42424242,  0.12121212,  0.02020202,  0.32323232,  0.11111111,\n        0.31313131,  0.68686869,  0.73737374,  1.        ,  0.01010101,\n        0.18181818,  0.76767677,  0.96969697,  0.35353535,  0.44444444,\n        0.72727273,  0.57575758,  0.74747475,  0.49494949,  0.75757576,\n        0.47474747,  0.37373737,  0.73737374,  0.96969697,  0.71717172,\n        0.42424242,  0.        ,  0.86868687,  0.81818182,  0.06060606])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_scale = (x - np.min(x)) / (np.max(x) - np.min(x))\n",
    "x_scale"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[87, 81],\n       [79, 75],\n       [14, 81],\n       [40, 72],\n       [99, 49],\n       [16, 79],\n       [86, 88],\n       [78, 96],\n       [20, 49],\n       [78, 24],\n       [36, 53],\n       [22, 28],\n       [45, 70],\n       [51, 36],\n       [27, 14],\n       [70, 81],\n       [ 1, 12],\n       [25,  8],\n       [75, 80],\n       [92, 31],\n       [66, 21],\n       [ 5, 27],\n       [53, 96],\n       [86, 95],\n       [58, 11],\n       [79, 90],\n       [ 2,  2],\n       [77, 76],\n       [ 0, 34],\n       [57, 78],\n       [10, 24],\n       [11, 42],\n       [50,  4],\n       [83, 54],\n       [93, 95],\n       [49, 51],\n       [59, 20],\n       [97,  3],\n       [ 3, 98],\n       [81, 26],\n       [35, 86],\n       [84, 68],\n       [50, 66],\n       [31, 61],\n       [81, 11],\n       [60, 11],\n       [80, 52],\n       [16, 10],\n       [96, 41],\n       [21, 58]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.random.randint(0,100,size=(50,2))\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 87.,  81.],\n       [ 79.,  75.],\n       [ 14.,  81.],\n       [ 40.,  72.],\n       [ 99.,  49.],\n       [ 16.,  79.],\n       [ 86.,  88.],\n       [ 78.,  96.],\n       [ 20.,  49.],\n       [ 78.,  24.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# X现在都是整形，那么先转为浮点数\n",
    "X = np.array(X, dtype=float)\n",
    "X[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 87.,  81.],\n       [ 79.,  75.],\n       [ 14.,  81.],\n       [ 40.,  72.],\n       [ 99.,  49.],\n       [ 16.,  79.],\n       [ 86.,  88.],\n       [ 78.,  96.],\n       [ 20.,  49.],\n       [ 78.,  24.]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最值归一化作用到矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "X[:,0] = (X[:,0] - np.min(X[:,0])) / (np.max(X[:,0]) - np.min(X[:,0]))\n",
    "X[:,1] = (X[:,1] - np.min(X[:,1])) / (np.max(X[:,1]) - np.min(X[:,1]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化，看看分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAFYVJREFUeJzt3W2MXFd9x/HfD4eA2wZMsVHJ2hsb1XGxyAuHUQBZKkGB2kklOwqUOogCVYoFbaqqtJYcUaUovEhoVCoh3IKrRgEkCIEia6UYuSpOFAmR1GuZJtjUaDEEe4MaE+K8wZCH/vtiZvF4s7NzZ+Y+nvv9SJZn7hzNnDsP/z3nfx6uI0IAgLS8rOoKAADyR3AHgAQR3AEgQQR3AEgQwR0AEkRwB4AEEdwBIEEEdwBIEMEdABJ0SVUvvHr16li/fn1VLw8AjXT06NGfRcSaYeUqC+7r16/X7OxsVS8PAI1k+4ks5UjLAECCCO4AkCCCOwAkiOAOAAkiuANAggjuAJAggjsAJGhocLd9j+2nbH9vwOO2/Rnbc7Yfs311/tUEAIwiyyKmeyV9VtIXBzx+vaSNvX9vkfQvvf8rd+DYvO4+dFJPnjuvy1et1J5tm3TjlqmqqwUAhRvaco+IhyX9fJkiOyV9MboekbTK9uvzquC4Dhyb123feFzz584rJM2fO6/bvvG4Dhybr7pqAFC4PHLuU5JO990/0ztWqbsPndT551+86Nj551/U3YdOVlQjAChPqQOqtnfbnrU9e/bs2UJf68lz50c6DgApyWPjsHlJ6/rur+0de4mI2C9pvyR1Op3I4bUHunzVSs0vEcgvX7WyyJdFSzCeMxrer/Ll0XKfkfSB3qyZt0p6NiJ+msPzTmTPtk1a+fIVFx1b+fIV2rNtU0U1QioYzxkN71c1hrbcbX9F0rWSVts+I+nvJb1ckiLic5IOSrpB0pykX0j606IqO4qFVgGtBeRtufEcvl8vVcb7VUTPoOm9jaHBPSJuHvJ4SP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AAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10645f908>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:,0], X[:,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.52808080808080804"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 均值\n",
    "np.mean(X[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.31109169557677196"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标准差\n",
    "np.std(X[:,0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Standardization（0均值标准化/均值方差归一化）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.random.randint(0,100,size=(50,2))\n",
    "X2 = np.array(X2, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2[:,0] = (X2[:,0] - np.mean(X2[:,0])) / np.std(X2[:,0])\n",
    "X2[:,1] = (X2[:,1] - np.mean(X2[:,1])) / np.std(X2[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 用可视化看看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD8CAYAAAB+UHOxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwO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pjfn2nqSb88fvlvRY/h08Jum6BPL9quMp6bOSrswfnyLpXyTtlfQDSefXnecJ8/+X+e99t6TvSPqtuvO8Iv+3SXpG0v/lv//rJF0v6fr8dUu6Kf98j2mVUX6J5v+GvuP/kKR3151nZgIDQEd1sgkIAEAAAIDOIgAAQEcRAACgowgAANBRBAAA6CgCAAB0FAEAADrq/wFhoR1uJdnNvQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10661b2e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:,0], X2[:,1], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9.7699626167e-17\n1.11022302463e-16\n1.0\n1.0\n"
     ]
    }
   ],
   "source": [
    "print(np.mean(X2[:,0]))\n",
    "print(np.mean(X2[:,1]))\n",
    "print(np.std(X2[:,0]))\n",
    "print(np.std(X2[:,1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
